// calculate convolution of a and b in GF(p)
// elements of a and b must integers in the range [0, p-1]
function c = gfconv(a, b, p)
  [lhs rhs] = argn();
  if rhs < 3
    p = 2;
  end
  
  if p < 2 | p ~= int(p)
    error('p must be an prime number');
  end
  
  if max(a) > p-1 | max(b) > p-1 | min(a) < 0 | min(b) < 0
    error('elements of a and b must integers in the range [0, p-1]')
  end

  if a ~= int(a)
    error('elements of a and b must integers in the range [0, p-1]')
  end
  
  if b ~= int(b)
    error('elements of a and b must integers in the range [0, p-1]')
  end

  if size(a, 1) ~= 1 | size(b,1) ~= 1
    error('a and b must be row vectors');
  end
  
  c = round(convol(a,b));
  c = modulo(c, p);
endfunction

